home *** CD-ROM | disk | FTP | other *** search
- Path: news2.ios.com!usenet
- From: vlad@gramercy.ios.com (Vlastimil Adamovsky)
- Newsgroups: comp.lang.c++
- Subject: Re: Problem: Passing pointer to function to Template Member function
- Date: Wed, 31 Jan 1996 21:14:51 GMT
- Organization: Internet Online Services
- Message-ID: <4eolj8$1fl@news2.ios.com>
- References: <391851586wnr@parkbayl.demon.co.uk>
- NNTP-Posting-Host: ppp-33.ts-7.hck.idt.net
- X-Newsreader: Forte Free Agent 1.0.82
-
- Martin Bayly <martin@parkbayl.demon.co.uk> wrote:
-
- >I have a parameterized list class. I would like one of the list class member functions to iterate
- >the list and for each object, call one of the object's own member functions. Thus my class is
- >defined as:
-
- >template <class T>
- >class List
- >{
- >public:
- > List( );
- > ~List( );
- > // other functions
- >> void Iterate(void (T::*pFunc)( ) );
- >private:
- > Node<T> itsHead;
- > ULONG itsCount;
- >};
-
- >i.e. I'm trying to define Iterate to take a pointer to a function of the object T, whatever T happens
- >to be. I get the following two compile errors (Visual C++ V4.0):
-
- All compilers are equal. But some of them are more equal than the
- others. That's why try this:
-
- template <class T>
- class List
- {
- public:
- typedef void (T::*PFUNC)( );
- List( ) {}
- ~List( ) {}
- // other functions
- void Iterate(PFUNC){}
- private:
- Node<T> itsHead;
- ULONG itsCount;
- };
-
- *******************************************
- * Vlastimil Adamovsky *
- * Smalltalk, C++ and Envelop development *
- *******************************************
-
-